using System;

namespace CleanCode
{
   // p. 46
   namespace PreferExceptions
   {
      public class TheWtfWay
      {
         private const int E_ERROR = 0;
         private const int E_OK = 1;

         public int Delete(Page page)
         {
            if (DeletePage(page) == E_OK)
            {
               if (Registry.DeleteReference(page.Name) == E_OK)
               {
                  if (ConfigKeys.DeleteKey(page.Name.MakeKey()) == E_OK)
                  {
                     Logger.Log("page deleted");
                  }
                  else
                  {
                     Logger.Log("configKey not deleted");
                  }
               }
               else
               {
                  Logger.Log("deleteReference from registry failed");
               }
               return E_OK;
            }
            else
            {
               Logger.Log("delete failed");
               return E_ERROR;
            }
         }

         private int DeletePage(object page)
         {
            throw new NotImplementedException();
         }
      }

      public class TheCleanCodeWay
      {
         public void Delete(Page page)
         {
            try
            {
               DeletePage(page);
               Registry.DeleteReference(page.Name);
               ConfigKeys.DeleteKey(page.Name.MakeKey());
            }
            catch (Exception ex)
            {
               Logger.Log(ex.Message);
            }
         }

         private void DeletePage(Page page)
         {
         }
      }

      public class TheEvenCleanerWay
      {
         public void Delete(Page page)
         {
            try
            {
               DeletePageAndAllReferences(page);
            }
            catch (Exception ex)
            {
               LogError(ex);
            }
         }

         private void DeletePageAndAllReferences(Page page)
         {
            DeletePage(page);
            Registry.DeleteReference(page.Name);
            ConfigKeys.DeleteKey(page.Name.MakeKey());
         }

         private void LogError(Exception ex)
         {
            Logger.Log(ex.Message);
         }

         private void DeletePage(Page page)
         {
         }
      }

      /*******************************************************/
      /*******************************************************/

      public class Page
      {
         public PageName Name
         {
            get { throw new NotImplementedException(); }
         }
         public class PageName
         {
            public string MakeKey()
            {
               throw new NotImplementedException();
            }
         }
      }
      public class Registry
      {
         public static int DeleteReference(Page.PageName pageName)
         {
            throw new NotImplementedException();
         }
      }
      public class ConfigKeys
      {
         public static int DeleteKey(string key)
         {
            throw new NotImplementedException();
         }
      }
      public class Logger
      {
         public static void Log(string msg)
         {
         }
      }
   }
}